<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        text-align: center;
        padding-top: 200px;
      }
      .mask {
        width: 100%;
        height: 100%;
        background-color: #00000030;
        position: fixed;
        top: 0;
        left: 0;
        transition: all 0.5s;
        display: none;
        opacity: 0;
      }

      .confirm {
        padding: 40px;
        border-radius: 10px;
        background-color: #fff;
        box-shadow: 0 0 6px 3px #ccc;
        position: absolute;
        top: 200px;
        left: 50%;
        transform: translate(-50%, -50%);
        text-align: center;
      }
      .footer {
        padding-top: 30px;
        display: flex;
      }
      .btn {
        padding: 20px;
        border-radius: 10px;
        border: 1px solid #ccc;
        cursor: pointer;
        user-select: none;
      }
      .cancel {
        margin-left: 40px;
      }
      .primary {
        background-color: #1045d6;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <button id="exit">退出登录</button>
    </div>
    <div class="mask">
      <div class="confirm">
        <h3>你确定要退出吗？</h3>
        <div class="footer">
          <div class="btn primary">确认</div>
          <div class="btn cancel">取消</div>
        </div>
      </div>
    </div>
    <script>
      var exitBtn = document.getElementById("exit");
      var mask = document.querySelector(".mask");
      exitBtn.onclick = function () {
        mask.style.display = "block";
        setTimeout(() => {
          mask.style.opacity = 1;
        });
      };

      mask.addEventListener("transitionend", function () {
        if (mask.style.opacity <= 0.01) {
          mask.style.display = "none";
        }
      });

      document.querySelector(".cancel").onclick = function () {
        mask.style.opacity = 0;
      };
      document.querySelector(".primary").onclick = function () {
        alert("退出登录");
        mask.style.opacity = 0;
      };
    </script>
  </body>
</html>
